class Direction:
    
    def __init__(self,name,offset,cost,oppositeDir=None):
        self.name = name
        self.xOffset, self.yOffset = offset
        self.offset = offset
        self.cost = cost
        self.oppositeDir = oppositeDir
        if oppositeDir:
            oppositeDir.oppositeDir = self

NORTH = Direction('N',(0,-1),2)
SOUTH = Direction('S',(0,1),2,NORTH)
EAST = Direction('E',(1,0),2)
WEST = Direction('W',(-1,0),2,EAST)
NORTHEAST = Direction('NE',(1,-1),3)
SOUTHWEST = Direction('SW',(-1,1),3,NORTHEAST)
NORTHWEST = Direction('NW',(-1,-1),3)
SOUTHEAST = Direction('SE',(1,1),3,NORTHWEST)

ALLDIRS = [NORTH,SOUTH,EAST,WEST,NORTHEAST,SOUTHWEST,NORTHWEST,SOUTHEAST]
CARDINALDIRS = [NORTH,SOUTH,EAST,WEST]
DIAGONALDIRS = [NORTHEAST,SOUTHWEST,NORTHWEST,SOUTHEAST]

def getDirFromOffset(offset):
    for dir in ALLDIRS:
        if offset[0] == dir.xOffset and offset[1] == dir.yOffset:
            return dir
    return None

def getNeighbor(fromCoords,direction):
    return direction.xOffset+fromCoords[0],direction.yOffset+fromCoords[1]